$(function() {
	var initHeight = window.innerHeight;//页面出事高度
	
	//记住密码
	rememberUser()
	
	$(".loginBtn").on("click",function(){
//		systemLogin();//系统登录
		systemLoginLocal();//系统登录
//		var username = $(".username").val();
//		var password = $(".password").val();
//		if(username=="admin" && password=="123"){
//			window.open("index.html","_self");
//		}else{
//			alert("用户名或密码错误！")
//		}
//		window.open("index.html","_self");
	})
	
	$(".input-text").on("focus",function(){
		$(".title").hide();
	})
	$(".input-text").on("click",function(){
		$(".title").hide();
	})
	
    $(window).on("resize", function() {
        var wH = window.innerHeight; // 当前窗口的高度
        if(!(wH<initHeight)){
        	$(".title").show();
		}
    })
    
    //记住密码
    function rememberUser(){
    	if(localStorage.getItem('username')){
    		$(".username").val(localStorage.getItem('username'));
    	}
    	if(localStorage.getItem('password')){
    		$(".password").val(localStorage.getItem('password'));
    	}
    }
    
    //系统登录
	function systemLogin() {
		var jsonObj = {
			"name": $(".username").val(),//用户名
			"password": $(".password").val()//密码
		};
		var jsonStr = json2str(jsonObj);
		$.ajax({
			type: "post",
			url: KddhBackUrl + "Address/systemLogin",
			data: jsonStr,
			contentType: 'application/json',
			dataType: 'json',
			success: function(result) {
				console.log("系统登录");
				console.log(result);
				var dataObj = result.data[0];
				if(dataObj.verify=="true"){
					//记住用户名、密码
					localStorage.setItem('username', $(".username").val());
					localStorage.setItem('password', $(".password").val());
//					getInfoFromWebView("login",{userID:jsonObj.userName,GroupTag:dataObj.PERSONID});//调用定位接口
					sessionStorage.setItem('userId', dataObj.userid);
					sessionStorage.setItem('userName', jsonObj.name);
					window.open("index.html", "_self");
				}else{
					$(".errorMSG span").css("display","block")
					$(".errorMSG span").text("用户名或密码错误！")
					setTimeout(function(){
						$(".errorMSG span").fadeOut(2000);
					},1000)
				}
			},
			error: function() {
				$(".errorMSG span").css("display","block")
				$(".errorMSG span").text("系统错误！")
				setTimeout(function(){
					$(".errorMSG span").fadeOut(2000);
				},1000)
			}
		});
	}
	
	//系统登录
    function systemLoginLocal() {
        var dataList = loginUserList.data;
        var dataObj = {
            verify:"false"
        }
        for(var i=0; i<dataList.length; i++){
            if(dataList[i].name == $(".username").val() && dataList[i].password == $(".password").val()){
                dataObj.userid = dataList[i].userid;
                dataObj.verify="true";
            }
        }
        if(dataObj.verify=="true"){
            //记住用户名、密码
            localStorage.setItem('username', $(".username").val());
            localStorage.setItem('password', $(".password").val());
            sessionStorage.setItem('userId', dataObj.userid);
            sessionStorage.setItem('userName', $(".username").val());
            window.open("index.html", "_self");
        }else{
            $(".errorMSG span").css("display","block")
            $(".errorMSG span").text("用户名或密码错误！")
            setTimeout(function(){
                $(".errorMSG span").fadeOut(2000);
            },1000)
        }
    }
    
	//调用安卓手机接口
	callAndroid();
	
	//调用安卓手机接口
	function callAndroid() {
		connectWebViewJavascriptBridge(function(bridge) {
			//监听推送的通知消息
			bridge.registerHandler("setPushInfo", function(data, responseCallback) {
				//document.getElementById("locInfo").innerHTML = ("data from Java: = " + data);
				var responseData = '1';
				getMsgInfo(data);//显示通知消息
				responseCallback(responseData);
			});
		})
	}
	//显示通知消息
	function getMsgInfo(msgInfoStr) {
		$(".msgInfo p").html(msgInfoStr);
		$(".msgInfo").show(); //通知信息弹框
		$(".msgInfo input").on("click", function() {
			$(".msgInfo").hide(); //通知信息弹框
		});
	}
})